package logic

import (
	"context"
	"shenzhou_srv/models"

	"shenzhou_srv/internal/svc"
	"shenzhou_srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *shenzhou.OrderListRequest) (*shenzhou.OrderListResponse, error) {
	var o models.Order
	orderlist, err := o.List()
	if err != nil {
		logx.Error("订单列表展示失败")
		return nil, err
	}
	var orderList []*shenzhou.OrderList

	for _, order := range orderlist {
		list := shenzhou.OrderList{
			UserId:      int64(order.UserId),
			OrderSn:     order.OrderSn,
			OrderPrice:  float32(order.OrderTotal),
			OrderStatus: int64(order.OrderStatus),
		}
		orderList = append(orderList, &list)
	}
	return &shenzhou.OrderListResponse{
		List: orderList,
	}, nil
}
